// https://umijs.org/config/
import { defineConfig } from 'umi';
import { join } from 'path';
import defaultSettings from './defaultSettings';
import proxy from './proxy';

const { REACT_APP_ENV } = process.env;

export default defineConfig({
  hash: true,
  antd: {},
  dva: {
    hmr: true,
  },
  layout: {
    // https://umijs.org/zh-CN/plugins/plugin-layout
    locale: true,
    siderWidth: 208,
    ...defaultSettings,
  },
  // https://umijs.org/zh-CN/plugins/plugin-locale
  locale: {
    // default zh-CN
    default: 'zh-CN',
    antd: true,
    // default true, when it is true, will use `navigator.language` overwrite default
    baseNavigator: true,
  },
  dynamicImport: {
    loading: '@ant-design/pro-layout/es/PageLoading',
  },
  targets: {
    ie: 11,
  },
  // umi routes: https://umijs.org/docs/routing
  routes: [
    {
      path: '/user',
      layout: false,
      routes: [
        {
          path: '/user/login',
          layout: false,
          name: 'login',
          component: './user/Login',
        },
        {
          path: '/user',
          redirect: '/user/login',
        },
        {
          name: 'register-result',
          icon: 'smile',
          path: '/user/register-result',
          component: './user/register-result',
        },
        {
          name: 'register',
          icon: 'smile',
          path: '/user/register',
          component: './user/register',
        },
        {
          component: '404',
        },
      ],
    },
    {
      path: '/dashboard',
      name: '工作台',
      icon: 'dashboard',
      component: './dashboard/index',
    },
    {
      path: '/article',
      name: '文章管理',
      icon: 'FormOutlined',
      routes: [
        {
          path: '/article',
          redirect: '/article/allArticle',
        },
        {
          name: '所有文章',
          icon: 'FormOutlined',
          path: '/article/allArticles',
          component: './article/allArticles/index',
        },
        {
          name: '分类管理',
          icon: 'smile',
          path: '/article/Classify',
          component: './article/Classify/index',
        },
        {
          name: '标签管理',
          icon: 'smile',
          path: '/article/Label',
          component: './article/Label/index',
        },
      ],
    },
    {
      path: '/page',
      name: '页面管理',
      icon: 'SnippetsOutlined',
      component: './page/index',
    },
    {
      path: '/Knowledge',
      name: '知识小测',
      icon: 'CopyOutlined',
      component: './Knowledge/index',
    },
    {
      path: '/Poster',
      name: '海报管理',
      icon: 'dashboard',
      component: './Poster/index',
    },
    {
      path: '/Comment',
      name: '评论管理',
      icon: 'MessageOutlined',
      component: './Comment/index',
    },
    {
      path: '/email',
      name: '邮件管理',
      icon: 'MailOutlined',
      component: './email/index',
    },
    {
      path: '/file',
      name: '文件管理',
      icon: 'StarOutlined',
      component: './file/index',
    },
    {
      path: '/SearchRecords',
      name: '搜索记录',
      icon: 'ProjectOutlined',
      component: './SearchRecords/index',
    },
    {
      path: '/AccessStatistics',
      name: '访问统计',
      icon: 'FolderOpenOutlined',
      component: './AccessStatistics/index',
    },
    {
      path: '/userManagement',
      name: '用户管理',
      icon: 'UserOutlined',
      component: './userManagement/index',
    },
    {
      path: '/System',
      name: '系统设置',
      icon: 'SettingOutlined',
      component: './System/index',
    },
    {
      path: '/',
      redirect: '/dashboard',
    },
    {
      component: '404',
    },
  ],
  // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  theme: {
    'primary-color': defaultSettings.primaryColor,
  },
  // esbuild is father build tools
  // https://umijs.org/plugins/plugin-esbuild
  esbuild: {},
  title: false,
  ignoreMomentLocale: true,
  proxy: proxy[REACT_APP_ENV || 'dev'],
  manifest: {
    basePath: '/',
  },
  // Fast Refresh 热更新
  fastRefresh: {},
  openAPI: [
    {
      requestLibPath: "import { request } from 'umi'",
      // 或者使用在线的版本
      // schemaPath: "https://gw.alipayobjects.com/os/antfincdn/M%24jrzTTYJN/oneapi.json"
      schemaPath: join(__dirname, 'oneapi.json'),
      mock: false,
    },
    {
      requestLibPath: "import { request } from 'umi'",
      schemaPath: 'https://gw.alipayobjects.com/os/antfincdn/CA1dOm%2631B/openapi.json',
      projectName: 'swagger',
    },
  ],
  nodeModulesTransform: {
    type: 'none',
  },
  mfsu: {},
  webpack5: {},
  exportStatic: {},
});
